<?php

/**
 * 用户后台管理
 * Created by PhpStorm.
 * User: yh
 * Date: 2017/6/7
 * Time: 11:16
 */
class Users extends Web_controller
{
    public function __construct()
    {
        parent::__construct();
        $this->userSession();
        $this->load->model('User_model', 'user_model');
        $this->load->model('Order_model', 'order_model');
        $this->load->helper('time');//时间工具类
    }

    /**
     * 根据手机号，查询用户信息
     */
    public function lists()
    {
        $mobile = $this->input->post('mobile');
        $data = array();
        if (empty($mobile))
        {
            $users = $this->user_model->getAllUser();
        }
        else
        {
            $users = $this->user_model->getUserByMobile($mobile);
        }
        for ($i = 0; $i < count($users); $i++)
        {
            //购买产品数量
            $users[$i]['cont'] = $this->order_model->getOrderCountByUid($users[$i]['uid']);
            //注册时间
            $users[$i]['register_time'] = _gettimestr( $users[$i]['register_time'],'Y-m-d H:i:s');
            //最后登录时间
            $users[$i]['last_time'] = _gettimestr( $users[$i]['last_time'],'Y-m-d H:i:s');
        }
        $data['content'] = $users;
        //----
        $data['title'] = "用户统计";
        $data['base_url']=$this->config->item('base_url');
        //测试OK
        $this->load->view('admin/header', $data);
        $this->load->view('admin/user_list');
        $this->load->view('admin/tail');
    }
}